﻿// SinsListDlg.cpp: 实现文件
//

#include "pch.h"
#include "JointSerialTest.h"
#include "SinsListDlg.h"
#include "afxdialogex.h"


// SinsListDlg 对话框

IMPLEMENT_DYNAMIC(SinsListDlg, CDialogEx)

SinsListDlg::SinsListDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_SINSLIST, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

SinsListDlg::~SinsListDlg()
{
}

void SinsListDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_SLIST, datalist);
}


BOOL SinsListDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	SetIcon(m_hIcon, TRUE);			// 设置大图标

	for (size_t k = 0; k < 8; k++)
	{
		datalist.InsertColumn(k, titles[k], LVCFMT_CENTER, width[k]);
	}
	return 0;
}

BEGIN_MESSAGE_MAP(SinsListDlg, CDialogEx)
	ON_MESSAGE(LISTMSG_GETSINS, addData)
END_MESSAGE_MAP()


// SinsListDlg 消息处理程序
LRESULT SinsListDlg::addData(WPARAM wParam, LPARAM lParam)
{
	IMUDATA* imudata = (IMUDATA*)wParam;
	CString nextContent;
	INT idx = 0;
	nextRowNUm = datalist.InsertItem(nextRowNUm, _T(""));
	nextContent.Format(_T("%d"), imudata->CNT);
	datalist.SetItemText(nextRowNUm, idx++, nextContent);
	nextContent.Format(_T("%f"), imudata->wx);
	datalist.SetItemText(nextRowNUm, idx++, nextContent);
	nextContent.Format(_T("%f"), imudata->wy);
	datalist.SetItemText(nextRowNUm, idx++, nextContent);
	nextContent.Format(_T("%f"), imudata->wz);
	datalist.SetItemText(nextRowNUm, idx++, nextContent);
	nextContent.Format(_T("%f"), imudata->fx);
	datalist.SetItemText(nextRowNUm, idx++, nextContent);
	nextContent.Format(_T("%f"), imudata->fy);
	datalist.SetItemText(nextRowNUm, idx++, nextContent);
	nextContent.Format(_T("%f"), imudata->fz);
	datalist.SetItemText(nextRowNUm, idx++, nextContent);
	nextContent.Format(_T("%d"), imudata->Tp1);
	datalist.SetItemText(nextRowNUm, idx++, nextContent);
	if (nextRowNUm++ > 20)
	{
		nextRowNUm = 0;
		datalist.DeleteAllItems();
	}
	return LRESULT();
}